---
title: "correlations"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(psych)
library(tidyverse)
library(ltm)
dat3 <- read.csv("raw dat_study3.csv")
dat4 <- read.csv("raw dat_study4.csv")
```

### Recode Reverse Coded Items
```{r}
dat3$rel_distant <- 8 - dat3$rel_distant
dat3$interact_diff <- 8 - dat3$interact_diff
dat3$authentic <- 8 - dat3$authentic
dat3$life_betterworse <- 8 - dat3$life_betterworse
dat3$conseq <- 8 - dat3$conseq

dat4$rel_distant <- 8 - dat4$rel_distant
dat4$interact_diff <- 8 - dat4$interact_diff
dat4$authentic <- 8 - dat4$authentic
dat4$life_betterworse <- 8 - dat4$life_betterworse
dat4$conseq <- 8 - dat4$conseq
```

### Burden Scale Calculations
```{r}
dat3$overall <- dat3 %>% dplyr::select(ruminate:conseq) %>% rowMeans(na.rm=T)
dat4$overall <- dat4 %>% dplyr::select(ruminate:conseq) %>% rowMeans(na.rm=T)

dat3$daily <- dat3 %>% dplyr::select(ruminate:avoid_social) %>% rowMeans(na.rm=T)
dat4$daily <- dat4 %>% dplyr::select(ruminate:avoid_social) %>% rowMeans(na.rm=T)

dat3$relharm <- dat3 %>% dplyr::select(rel_distant:authentic) %>% rowMeans()
dat4$relharm <- dat4 %>% dplyr::select(rel_distant:authentic) %>% rowMeans()

dat3$extpull <- dat3 %>% dplyr::select(obligate:guilty) %>% rowMeans(na.rm=T)
dat4$extpull <- dat4 %>% dplyr::select(obligate:guilty) %>% rowMeans(na.rm=T)

dat3$antconsq <- dat3 %>% dplyr::select(uncomf_convo:conseq) %>% rowMeans(na.rm=T)
dat4$antconsq <- dat4 %>% dplyr::select(uncomf_convo:conseq) %>% rowMeans(na.rm=T)
```

### Other Scale Calculations
```{r}
dat4$cope <- dat4 %>% dplyr::select(cope1:cope3) %>% rowMeans(na.rm=T)
summary(dat4$cope)
coping <- dat4 %>% select(cope1:cope3)
cronbach.alpha(coping) #0.739

dat4$authen <- dat4 %>% dplyr::select(authen1:authen4) %>% rowMeans(na.rm=T)
summary(dat4$authen)
authen <- dat4 %>% dplyr::select(authen1:authen4)
cronbach.alpha(authen, na.rm=T)

dat4$support <- dat4 %>% dplyr::select(support1:support6) %>% rowMeans(na.rm=T)
summary(dat4$support)
support <- dat4 %>% dplyr::select(support1:support6)
cronbach.alpha(support, na.rm=T)

dat4$physwb <- dat4 %>% dplyr::select(wb1:wb9) %>% rowMeans(na.rm=T)
summary(dat4$physwb)
physwb <- dat4 %>% dplyr::select(wb1:wb9)
cronbach.alpha(physwb, na.rm=T)

dat4$flourish <- dat4 %>% dplyr::select(flourish1:flourish8) %>% rowMeans(na.rm=T)
summary(dat4$flourish)
flourish <- dat4 %>% dplyr::select(flourish1:flourish8)
cronbach.alpha(flourish, na.rm=T)

dat4$lonely3 <- 5 - dat4$lonely3
dat4$lonely6 <- 5 - dat4$lonely6

dat4$lonely <- dat4 %>% dplyr::select(lonely1:lonely8) %>% rowMeans(na.rm=T)
summary(dat4$lonely)
lonely <- dat4 %>% dplyr::select(lonely1:lonely8)
cronbach.alpha(lonely, na.rm=T)

dat3$panas_neg <- dat3 %>% dplyr::select(PANAS_afraid, PANAS_irritable, PANAS_guilty, PANAS_scared, PANAS_nervous, PANAS_ashamed, PANAS_hostile, PANAS_jittery, PANAS_disgust, PANAS_upset,PANAS_distressed, PANAS_selfdissatis, PANAS_sad, PANAS_blue, PANAS_alone, PANAS_blameworthy) %>% rowMeans(na.rm=T)
summary(dat3$panas_neg)
panas_neg <- dat3 %>% dplyr::select(PANAS_afraid, PANAS_irritable, PANAS_guilty, PANAS_scared, PANAS_nervous, PANAS_ashamed, PANAS_hostile, PANAS_jittery, PANAS_disgust, PANAS_upset,PANAS_distressed, PANAS_selfdissatis, PANAS_sad, PANAS_blue, PANAS_alone, PANAS_blameworthy)
cronbach.alpha(panas_neg, na.rm=T)

dat3$panas_pos <- dat3 %>% dplyr::select(PANAS_alert, PANAS_determined, PANAS_enthusiastic, PANAS_excited, PANAS_attentive, PANAS_calm, PANAS_active, PANAS_strong, PANAS_relaxed, PANAS_happy, PANAS_joyful, PANAS_ease) %>% rowMeans(na.rm=T)
summary(dat3$panas_pos)
panas_pos <- dat3 %>% dplyr::select(PANAS_alert, PANAS_determined, PANAS_enthusiastic, PANAS_excited, PANAS_attentive, PANAS_calm, PANAS_active, PANAS_strong, PANAS_relaxed, PANAS_happy, PANAS_joyful, PANAS_ease)
cronbach.alpha(panas_pos, na.rm=T)
```

### Correlations
```{r}
cor.test(dat4$daily, dat4$cope)
cor.test(dat4$relharm, dat4$cope)
cor.test(dat4$extpull, dat4$cope)
cor.test(dat4$antconsq, dat4$cope)
cor.test(dat4$overall, dat4$cope)
cor.test(dat4$burden, dat4$cope)

cor.test(dat4$daily, dat4$authen)
cor.test(dat4$relharm, dat4$authen)
cor.test(dat4$extpull, dat4$authen)
cor.test(dat4$antconsq, dat4$authen)
cor.test(dat4$overall, dat4$authen)
cor.test(dat4$burden, dat4$authen)

cor.test(dat4$daily, dat4$support)
cor.test(dat4$relharm, dat4$support)
cor.test(dat4$extpull, dat4$support)
cor.test(dat4$antconsq, dat4$support)
cor.test(dat4$overall, dat4$support)
cor.test(dat4$burden, dat4$support)

cor.test(dat4$daily, dat4$physwb)
cor.test(dat4$relharm, dat4$physwb)
cor.test(dat4$extpull,dat4$physwb)
cor.test(dat4$antconsq, dat4$physwb)
cor.test(dat4$overall, dat4$physwb)
cor.test(dat4$burden, dat4$physwb)

cor.test(dat4$daily, dat4$lonely)
cor.test(dat4$relharm, dat4$lonely)
cor.test(dat4$extpull,dat4$lonely)
cor.test(dat4$antconsq, dat4$lonely)
cor.test(dat4$overall, dat4$lonely)
cor.test(dat4$burden, dat4$lonely)

cor.test(dat4$daily, dat4$flourish)
cor.test(dat4$relharm, dat4$flourish)
cor.test(dat4$extpull,dat4$flourish)
cor.test(dat4$antconsq, dat4$flourish)
cor.test(dat4$overall, dat4$flourish)
cor.test(dat4$burden, dat4$flourish)

cor.test(dat3$daily, dat3$panas_pos)
cor.test(dat3$relharm, dat3$panas_pos)
cor.test(dat3$extpull,dat3$panas_pos)
cor.test(dat3$antconsq, dat3$panas_pos)
cor.test(dat3$overall, dat3$panas_pos)
cor.test(dat3$burden, dat3$panas_pos)

cor.test(dat3$daily, dat3$panas_neg)
cor.test(dat3$relharm, dat3$panas_neg)
cor.test(dat3$extpull,dat3$panas_neg)
cor.test(dat3$antconsq, dat3$panas_neg)
cor.test(dat3$overall, dat3$panas_neg)
cor.test(dat3$burden, dat3$panas_neg)
```

### Linear Regressions
```{r}
pospan <- lm(panas_pos ~ daily+relharm+extpull+antconsq, dat3)
summary(pospan)
negpan <- lm(panas_neg ~ daily+relharm+extpull+antconsq, dat3)
summary(negpan)
cope <- lm(cope ~ daily+relharm+extpull+antconsq, dat4)
summary(cope)
authen <- lm(authen ~ daily+relharm+extpull+antconsq, dat4)
summary(authen)
support <- lm(support ~ daily+relharm+extpull+antconsq, dat4)
summary(support)
physwb <- lm(physwb ~ daily+relharm+extpull+antconsq, dat4)
summary(physwb)
flour <- lm(flourish ~ daily+relharm+extpull+antconsq, dat4)
summary(flour)
lone <- lm(lonely ~ daily+relharm+extpull+antconsq, dat4)
summary(lone)
```

#Discriminant Validity scale calculations & correlations
```{r}
#rumination
dat3$rum2 <- 8 - dat3$rum2
dat3$rum3 <- 8 - dat3$rum3
dat3$rum6 <- 8 - dat3$rum6

dat3$ruminscale <- dat3 %>% dplyr::select(rum1:rum6) %>% rowMeans(na.rm=T)
describe(dat3$ruminscale)
ruminscale <- dat3 %>% dplyr::select(rum1:rum6) 
psych::alpha(ruminscale)
cronbach.alpha(ruminscale, na.rm=T)
alpha(ruminscale)

dat3$ruminscale2 <- dat3 %>% dplyr::select(rum1, rum3:rum5) %>% rowMeans(na.rm=T)
describe(dat3$ruminscale2)
ruminscale2 <- dat3 %>% dplyr::select(rum1, rum3:rum5)
cronbach.alpha(ruminscale2,na.rm=T)
cor.test(dat3$ruminscale, dat3$daily)
cor.test(dat3$ruminscale, dat3$relharm)
cor.test(dat3$ruminscale, dat3$antconsq)
cor.test(dat3$ruminscale, dat3$extpull)
cor.test(dat3$ruminscale, dat3$overall)

#Tilberg cognitive preoccupation - consequences
dat3$Tilb_consq <- dat3 %>% dplyr::select(TSS_con1:TSS_con5) %>% rowMeans(na.rm=T)
describe(dat3$Tilb_consq)
Tilb_consq <- dat3 %>% dplyr::select(TSS_con1:TSS_con5)
cronbach.alpha(Tilb_consq, na.rm=T)
cor.test(dat3$Tilb_consq, dat3$daily)
cor.test(dat3$Tilb_consq, dat3$relharm)
cor.test(dat3$Tilb_consq, dat3$antconsq)
cor.test(dat3$Tilb_consq, dat3$extpull)
cor.test(dat3$Tilb_consq, dat3$overall)


#Tilberg cognitive preoccupation - ruminative thought
dat3$Tilb_rum <- dat3 %>% dplyr::select(TSS_rum1:TSS_rum5) %>% rowMeans(na.rm=T)
describe(dat3$Tilb_rum)
Tilb_rum <- dat3 %>% dplyr::select(TSS_rum1:TSS_rum5)
cronbach.alpha(Tilb_rum, na.rm=T)
cor.test(dat3$Tilb_rum, dat3$daily)
cor.test(dat3$Tilb_rum, dat3$relharm)
cor.test(dat3$Tilb_rum, dat3$antconsq)
cor.test(dat3$Tilb_rum, dat3$extpull)
cor.test(dat3$Tilb_rum, dat3$overall)

#state authenticity
dat3$authen2 <- 8 - dat3$authen2
dat3$authenscale <- dat3 %>% dplyr::select(authen1:authen3) %>% rowMeans(na.rm=T)
describe(dat3$authenscale)
authenscale <- dat3 %>% dplyr::select(authen1:authen3)
cronbach.alpha(authenscale, na.rm=T)
psych::alpha(authenscale)

cor.test(dat3$authenscale, dat3$daily)
cor.test(dat3$authenscale, dat3$relharm)
cor.test(dat3$authenscale, dat3$antconsq)
cor.test(dat3$authenscale, dat3$extpull)
cor.test(dat3$authenscale, dat3$overall)
```




